<template>
  <div class="table">
    <table>
      <RowTable
        v-for="(item, index) in goodsArr"
        :key="index"
        :obj="item.goodsName"
        v-model="item.count"
        @input="item.count = +$event"
      ></RowTable>
    </table>
    <p>All Number : {{ sum }}</p>
  </div>
</template>

<script>
import RowTable from "@/components/RowTable.vue";
export default {
  components: {
    RowTable,
  },
  props: {},
  data() {
    return {
      goodsArr: [
        {
          count: 0,
          goodsName: "Watermelon",
        },
        {
          count: 0,
          goodsName: "Banana",
        },
        {
          count: 0,
          goodsName: "Orange",
        },
        {
          count: 0,
          goodsName: "Pineapple",
        },
        {
          count: 0,
          goodsName: "Strawberry",
        },
      ],
    };
  },
  computed: {
    sum: {
      get() {
        return this.goodsArr.reduce(
          (sum, item) => (sum = sum + item.count * 1),
          0
        );
      },
    },
  },
  watch: {},
  created() {},
  methods: {},
};
</script>

<style scoped>
.table {
  width: 400px;
  border: 1px solid;
}
</style>
